using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.DataHelper;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class SaleWitkey : Shop, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected HtmlInputHidden HiddenType;
	protected DropDownList DropDownList_WitkeyTypeOne;
	protected DropDownList DropDownList_WitkeyTypeTwo;
	protected UpdatePanel UpdatePanel1;
	protected TextBox WitkeyTaskTitle;
	protected TextBox WitkeyContent;
	protected TextBox WitkeyPrice;
	protected HtmlTableRow trWitkey4;
	protected DropDownList DropDownList_zbPrice;
	protected HtmlTableRow trWitkey5;
	protected DropDownList DropDownList_ValidDay;
	protected HtmlTableRow trWitkey3;
	protected TextBox TextBox_Name;
	protected TextBox TextBox_Email;
	protected TextBox TextBox_Phone;
	protected DropDownList DropDownList_Mode;
	protected Button Button_Ok;
	protected Button Button_Back;
	protected HtmlForm form1;
	protected HtmlGenericControl myhtml;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		if (!base.user.CheckUserLogin())
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/NotLogin", new string[0]), "Passport/Login.aspx?ComeUrl=" + this.InstallDir + "SaleProduct.aspx");
		}
		try
		{
			Template.BindTemplateToPage(this.Page, "SaleProduct");
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
		}
	}
	protected void Initpage()
	{
	}
	protected void DropDownList_WitkeyTypeOne_SelectedIndexChanged(object sender, EventArgs e)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.DropDownList_WitkeyTypeTwo.DataSource = shop_Witkey.GetWitkeyTypeByTypeFId(int.Parse(this.DropDownList_WitkeyTypeOne.SelectedValue));
		this.DropDownList_WitkeyTypeTwo.DataBind();
	}
	public bool CheckInput()
	{
		string value = this.HiddenType.Value;
		string text = string.Empty;
		if (value == "1")
		{
			if (this.DropDownList_WitkeyTypeOne.SelectedValue == "-1")
			{
				text = text + "悬赏" + Language.Get("Witkey/WitkeyTypeNull") + "<br/>";
			}
			if (this.WitkeyTaskTitle.Text.Trim() == string.Empty)
			{
				text = text + "悬赏" + Language.Get("Witkey/WitkeyTaskTitleNull") + "<br/>";
			}
			if (this.WitkeyContent.Text.Trim() == string.Empty)
			{
				text = text + "悬赏" + Language.Get("Witkey/WitkeyContentNull") + "<br/>";
			}
			if (this.TextBox_Name.Text.Trim() == string.Empty)
			{
				text = text + "悬赏" + Language.Get("Witkey/UserNameNull") + "<br/>";
			}
			if (!Text.IsNumber(this.WitkeyPrice.Text.Trim()))
			{
				text = text + "悬赏" + Language.Get("Witkey/WitkeyPriceNull") + "<br/>";
			}
			if (!SaleWitkey.IsEmail(this.TextBox_Email.Text))
			{
				text = text + Language.Get("Witkey/WitkeyEmailNull") + "<br/>";
			}
			if (!SaleWitkey.IsMobileNum(this.TextBox_Phone.Text))
			{
				text += Language.Get("Witkey/WitkeyPhoneNull");
			}
		}
		else
		{
			if (this.DropDownList_WitkeyTypeOne.SelectedValue == "-1")
			{
				text = text + "招标" + Language.Get("Witkey/WitkeyTypeNull") + "<br/>";
			}
			if (this.WitkeyTaskTitle.Text.Trim() == string.Empty)
			{
				text = text + "招标" + Language.Get("Witkey/WitkeyTaskTitleNull") + "<br/>";
			}
			if (this.WitkeyContent.Text.Trim() == string.Empty)
			{
				text = text + "招标" + Language.Get("Witkey/WitkeyContentNull") + "<br/>";
			}
			if (this.TextBox_Name.Text.Trim() == string.Empty)
			{
				text = text + "招标" + Language.Get("Witkey/UserNameNull") + "<br/>";
			}
			if (this.DropDownList_zbPrice.SelectedValue == "-1")
			{
				text = text + "招标" + Language.Get("Witkey/WitkeyPriceNull") + "<br/>";
			}
			if (!SaleWitkey.IsEmail(this.TextBox_Email.Text))
			{
				text = text + Language.Get("Witkey/WitkeyEmailNull") + "<br/>";
			}
			if (!SaleWitkey.IsMobileNum(this.TextBox_Phone.Text))
			{
				text += Language.Get("Witkey/WitkeyPhoneNull");
			}
		}
		bool result;
		if (text.Trim().Length > 0)
		{
			this.WriteErrMsg("", text, "");
			result = false;
		}
		else
		{
			result = true;
		}
		return result;
	}
	public static bool IsEmail(string _value)
	{
		Regex regex = new Regex("^\\w+([-+.]\\w+)*@(\\w+([-.]\\w+)*\\.)+([a-zA-Z]+)+$", RegexOptions.IgnoreCase);
		return regex.Match(_value).Success;
	}
	public static bool IsMobileNum(string _value)
	{
		Regex regex = new Regex("^13\\d{9}$", RegexOptions.IgnoreCase);
		return regex.Match(_value).Success;
	}
	protected void Button_Ok_Click(object sender, EventArgs e)
	{
		if (this.CheckInput())
		{
			decimal ww_xsPrice = 0m;
			string ww_zbPrice = string.Empty;
			string ww_Email = this.TextBox_Email.Text.Trim();
			string ww_Phone = this.TextBox_Phone.Text.Trim();
			string ww_xsModel = string.Empty;
			int num = int.Parse(this.HiddenType.Value);
			string ww_Title = this.WitkeyTaskTitle.Text.Trim();
			string ww_Content = this.WitkeyContent.Text.Trim();
			string text = this.DropDownList_WitkeyTypeOne.SelectedItem.Text;
			string text2 = this.DropDownList_WitkeyTypeTwo.SelectedItem.Text;
			int userID = base.user.UserID;
			string ww_UserName = this.TextBox_Name.Text.Trim();
			DateTime now = DateTime.Now;
			DateTime ww_EndTime = now.AddDays((double)Convert.ToInt32(this.DropDownList_ValidDay.SelectedValue));
			int ww_Statu;
			if (num == 1)
			{
				ww_xsPrice = Convert.ToDecimal(this.WitkeyPrice.Text.Trim());
				ww_xsModel = this.DropDownList_Mode.SelectedItem.Text;
				ww_Statu = 1;
			}
			else
			{
				ww_zbPrice = this.DropDownList_zbPrice.SelectedItem.Text;
				ww_Statu = 2;
			}
			Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
			DataTable dataTable = shop_Witkey.AddWitkey(num, "", ww_Title, ww_Content, text, text2, userID, ww_UserName, now, ww_EndTime, ww_zbPrice, ww_xsPrice, 0, "", ww_Statu, ww_xsModel, ww_Email, ww_Phone);
			this.WriteSuccessMsg("", Language.Get("Witkey/SaleWitkeySuccess"), "/Witkey/ShowWitkey.aspx?ww_ID=" + dataTable.Rows[0]["ww_ID"].ToString());
		}
	}
	protected void Button_Back_Click(object sender, EventArgs e)
	{
		base.Server.Transfer("SaleWitkey.aspx");
	}
}
